<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增服务信息')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-node-add">
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">服务编号：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="serviceCode" id="serviceCode" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">服务名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="serviceName" id="serviceName" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">节点编号：</label>
				<div class="col-sm-8">
					<select id="nodeCode" name="nodeCode" class="form-control" th:with="nodes=${@node.getCacheNodeInfoAll()}" onchange="fillDeployIp()" required>
						<option th:each="node:${nodes}" th:title="${node.ip}" th:value="${node.nodeCode}" th:text="${node.hostname}" th:disabled="${node.status == 0}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">部署IP：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="deployIp" id="deployIp" readonly required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">心跳访问端口：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="port" id="port" value="8080" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">健康检查请求地址：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="healthCheckUrl" id="healthCheckUrl" value="heartbeat" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required" title="启动服务的脚本路径">启动服务脚本路径：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="startupScriptPath" id="startupScriptPath" value="start.sh" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required" title="停止服务的脚本路径">停止服务脚本路径：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="stopScriptPath" id="stopScriptPath" value="stop.sh" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required" title="服务运行期间产生的日志路径">服务日志路径：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="logPath" id="logPath" value="logs" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required" title="预估服务的启动时间 单位:秒">预计启动时长(秒)：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="estimatedStartupTime" id="estimatedStartupTime" value="30" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">是否自启：</label>
				<div class="col-sm-8">
					<label class="toggle-switch switch-solid">
						<input type="checkbox" id="selfStart" checked>
						<span></span>
					</label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">监控状态：</label>
				<div class="col-sm-8">
					<label class="toggle-switch switch-solid">
						<input type="checkbox" id="status">
						<span></span>
					</label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<textarea id="remark" name="remark" class="form-control"></textarea>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "system/service";

		$(function() {
			fillDeployIp();
		});

		$("#form-node-add").validate({
			onkeyup: false,
			rules:{
				port:{
					digits:true,
					range:[0,65535]
				}
			},
			messages: {
		    },
		    focusCleanup: true
		});

		function submitHandler() {
	        if ($.validate.form()) {
				var data = $('#form-node-add').serializeArray();
				var selfStart = $("input[id='selfStart']").is(':checked') == true ? 1 : 0;
				var status = $("input[id='status']").is(':checked') == true ? 1 : 0;
				data.push({"name": "status", "value": status});
				data.push({"name": "selfStart", "value": selfStart});
				$.operate.save(prefix + "/add", data);
	        }
	    }

		function fillDeployIp() {
			//获取被选中的option标签
			var deployIp = $('select  option:selected').attr('title');
			$("#deployIp").val(deployIp);
		}
	</script>
</body>
</html>
